<?php
declare(strict_types=1);

namespace app\model;

use think\Model;

class MerchantRechargeRecord extends Model
{
    protected $autoWriteTimestamp = true;

    // 充值状态常量
    const STATUS_UNPAID = 0; // 未支付
    const STATUS_PAID = 1; // 已支付
    const STATUS_RECHARGED = 2; // 已充值
    const STATUS_CANCELLED = 3; // 已取消

    // 充值方式常量
    const TYPE_WECHAT = 1; // 微信
    const TYPE_ALIPAY = 2; // 支付宝
    const TYPE_TRANSFER = 3; // 对公转账

    // 关联商家
    public function merchant()
    {
        return $this->belongsTo(Merchant::class);
    }

    // 关联管理员
    public function admin()
    {
        return $this->belongsTo(Admin::class);
    }

    // 获取状态文字
    public function getStatusTextAttr()
    {
        $status = [
            self::STATUS_UNPAID => '未支付',
            self::STATUS_PAID => '已支付',
            self::STATUS_RECHARGED => '已充值',
            self::STATUS_CANCELLED => '已取消'
        ];
        return $status[$this->status] ?? '未知';
    }

    // 获取充值方式文字
    public function getRechargeTypeTextAttr()
    {
        $types = [
            self::TYPE_WECHAT => '微信',
            self::TYPE_ALIPAY => '支付宝',
            self::TYPE_TRANSFER => '对公转账'
        ];
        return $types[$this->recharge_type] ?? '未知';
    }
} 